package com.cndw.kungfu.ext;

import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import com.cndw.kungfu.config.ConstantsConfig;

public class LangConfigLib {

	private static final String configFile = "lang.config.properties";
	
	private static Map<String, String[]> configVales = new HashMap<String, String[]>();
	

	static {
		load();
	}

	public static void load() {
		try {
			Properties temp = new Properties();
			InputStreamReader input = new InputStreamReader(LangConfigLib.class.getResourceAsStream("/" + ConstantsConfig.getLocaleResource() + configFile),
					"UTF-8");
			temp.load(input);
			input.close();
			
			for (Map.Entry<Object, Object> it : temp.entrySet()) {
				String key = it.getKey().toString().trim();
				String value = it.getValue().toString().trim();
				if (key != null && value != null) {
					configVales.put(key, value.split(","));
				}
			}	
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static String[] getConfigs(String key){
		if (!configVales.containsKey(key)) {
			LogUtil.getMain().error("config value call err on "+ key);
		}
		return configVales.get(key);
	}
	
	public static String getByIndex(String key,int index){
		String[] configs  = getConfigs(key);
		if (configs != null && configs.length > index) {
			return configs[index];
		}
		LogUtil.getMain().error("config value call err on "+ key + " -> "+index);
		return null;
	}
	
	public static void clear(){		
		load();
	}
	
	


}
